package com.poem.controller;

import com.poem.dto.AuthorsPageQueryDTO;
import com.poem.dto.TypesQueryDTO;
import com.poem.entity.Authors;
import com.poem.entity.Types;
import com.poem.result.PageResult;
import com.poem.result.Result;
import com.poem.service.TypesService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: TypesController
 * @Author: YLY
 * @Description:
 * @Date: 2025/10/15
 * @Version: 1.0
 */

@RestController
@RequestMapping("/types")
@Slf4j
public class TypesController {

    @Resource
    private TypesService typeService;

    /**
     * 查询所有类型
     * @return
     */
    @GetMapping("/list")
    public Result list() {
       List<Types> typeList =  typeService.queryAllTypes();
       return Result.success(typeList);
    }

    /**
     * 添加题材
     * @param type
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Types type){
        log.info("添加题材:{}", type);
        typeService.addType(type);
        return Result.success();
    }

    /**
     * 修改题材
     * @param type
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody Types type){
        log.info("修改题材:{}", type);
        typeService.updateType(type);
        return Result.success();
    }

    /**
     * 删除题材
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除题材:{}", ids);
        typeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 分页查询
     * @param typesQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<Types>> pageQuery(TypesQueryDTO typesQueryDTO ){
        log.info("分页查询：{}", typesQueryDTO);
        PageResult<Types> pageResult = typeService.pageQuery(typesQueryDTO);
        return Result.success(pageResult);
    }
}
